package com.itheima.controller;

import com.itheima.pojo.PageResult;
import com.itheima.pojo.Result;
import com.itheima.pojo.Student;
import com.itheima.pojo.StudentQueryParam;
import com.itheima.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/students")
public class StudentController {
    @Autowired
    private StudentService studentService;

    //查询所有数据
    @GetMapping
    public Result page(StudentQueryParam studentQueryParam){
        PageResult pageResult = studentService.page(studentQueryParam);
        return Result.success(pageResult);
    }

    //添加学员数据
    @PostMapping
    public Result inster(@RequestBody Student student){
        studentService.inster(student);
        return Result.success();
    }

    //根据id查询学员信息
    @GetMapping("/{id}")
    public Result get(@PathVariable Integer id){
        Student student = studentService.get(id);
        return Result.success(student);
    }

    //修改学员信息
    @PutMapping
    public Result update(@RequestBody Student student){
        studentService.update(student);
        return Result.success();
    }
    //删除学员信息
    @DeleteMapping("/{ids}")
    public Result delete(@PathVariable List<Integer> ids){
        studentService.deleteByIds(ids);
        return Result.success();
    }
    //违纪扣分处理
    @PutMapping("/violation/{id}/{score}")
    public Result violation(@PathVariable Integer id,@PathVariable Short score){
        studentService.violation(id,score);
        return Result.success();
    }

}
